package logic

import (
	"context"
	"errors"
	"goods_srv/cache"

	"goods_srv/goods"
	"goods_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type DelCartLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewDelCartLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DelCartLogic {
	return &DelCartLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 删除购物车
func (l *DelCartLogic) DelCart(in *goods.DelCartRequest) (*goods.DelCartResponse, error) {
	// todo: add your logic here and delete this line

	err := cache.DeleteCart(int(in.UserId), int(in.GoodsId))
	if err != nil {
		logx.Error("删除购物车失败")
		return nil, errors.New("删除购物车失败")
	}

	return &goods.DelCartResponse{}, nil
}
